<?php

include("class.base.php");
if (!sisse_logitud()) { header("Location: index.php"); die(); }

$tabel1 = kriips($_GET["t"]);
$xtabel = htmlspecialchars($_GET["t"]);
$t_id = $_GET["id"];
settype($t_id, 'int');

$pealkiri1 = "Kustuta ".$tabel1;
$sisu =<<<SISU
<form action="" method="POST">
	<table width="100%">
SISU;
$tabelid = get_tables();
if (in_array($xtabel, $tabelid)) {
	$paring = mysql_query("SELECT * FROM $xtabel WHERE id=$t_id");
	if (mysql_num_rows($paring) > 0) {
		if (isset($_POST["kustuta"])) {
			mysql_query("DELETE FROM $xtabel WHERE id=$t_id");
			$teade = "Kustutatud!";
		}
		else {
			$sisu .=<<<SISU
				<tr><td>Oled kindel, et soovid $tabel1 kustutada?</td></tr>
				<tr><td><input type="submit" name="kustuta" value="Jah" /> <a href="index.php">Ei</a></td></tr>
SISU;
		}
	} else { $viga = "Tabelis pole sellist kirjet olemas."; }
} else { $viga = "Tabelit pole olemas."; }
$sisu .=<<<SISU
	</table>
</form>
SISU;
include("kujundus.php");
?>
